<?php
    $user_name = "SomeUser"; // replace your user name within the 2x "
    $password = "SomePass"; // replace your password within the 2x "
    $database_name = "SomeDB"; // replace the database name within the 2x "
    $table_name = "SomeTable"; // replace the table name within the 2x "



    $key = $_POST["customer_key"];
    $first_name = $_POST["first_name"];
    $last_name = $_POST["last_name"];
        
    $dbh = mysqli_connect("localhost", $user_name, $password, $database_name);
    if (!$dbh)
    {
        die("Not connected : " . mysqli_error($dbh));
    }
    else
    {
        $query = "SELECT * FROM `$table_name` WHERE customer_key = '$key'";
        $result = mysqli_query($dbh,$query);
        if (!$result)
        {
            echo 'Could not run query: ' . mysqli_error($dbh);
        }
        else
        {
            $row = mysqli_fetch_row($result);
            
            if ($row >= 1)
            {
                echo ("key_in_list");
            }
            else
            {
                $query = "
                        INSERT INTO `$database_name`.`$table_name` (
                        `first_name` ,
                        `last_name` ,
                        `customer_key`                            
                        )
                        VALUES (
                        '$first_name', '$last_name', '$key'
                        )";                    
                $result = mysqli_query($dbh,$query);
                echo ("new_key_added");                        
            }
        }
        mysqli_close($dbh);                        
    }
?>
